package com.trust.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.trust.agri.response.ResponseResult;
import com.trust.agri.sign.validate.SaveValidate;
import com.trust.annotation.SYQLog;
import com.trust.entity.Medicine;
import com.trust.entity.Param.MedicineListParam;
import com.trust.entity.VO.MedicineListVO;
import com.trust.entity.VO.MedicineVO;
import com.trust.service.MedicineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("/api/medicine")
@Api(value = "基础设置 - 物料管理 药材", tags = "基础设置 - 物料管理 药材")
public class MedicineController {

    @Resource
    private MedicineService service;

    @PostMapping("/save")
    @ApiOperation("新增药材")
    @SYQLog(type = "新增药材", name = "物料管理 药材")
    public ResponseResult<Medicine> save(@Validated(SaveValidate.class) @RequestBody MedicineVO param){
        Medicine medicine = service.saveAndUpdate(param);
        return ResponseResult.ok(medicine);
    }


    @PostMapping("/list")
    @ApiOperation("药材列表")
    public ResponseResult<Page<MedicineListVO>> list(@RequestBody MedicineListParam param){
        Page<MedicineListVO> page = service.list(param);
        return ResponseResult.ok(page);
    }
}
